package com.hp.bon.sgw.wh.mml.repositories;

import java.util.concurrent.ConcurrentLinkedQueue;

import com.hp.bon.sgw.wh.mml.common.LogEntity;
import com.hp.bon.sgw.wh.mml.common.MsgUtils;

public class LogMsgRepository {

	private static ConcurrentLinkedQueue<LogEntity> logMsgQueue = new ConcurrentLinkedQueue<LogEntity>();
	
	public static void offerLogMsg(String logMsg){
		if(!PropertyRepository.isLogMsgEnable() || logMsg==null){
			return;
		}
		LogEntity logEntity = new LogEntity();
		logEntity.setLogTime(MsgUtils.getNowDate());
		logEntity.setLogMsg(logMsg);
		logMsgQueue.offer(logEntity);
	}
	
	public static LogEntity pollLogMsg(){
		return logMsgQueue.poll();
	}
	
	public static String pollLogMsgLine(){
		LogEntity logEntity = pollLogMsg();
		if(logEntity==null){
			return null;
		}
		String logMsg = logEntity.getLogTime() + " - " + logEntity.getLogMsg();
		return logMsg;
	}
}
